package com.hb.trade.server.project.order.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.parent.MPCommonEntity;
import com.hb.core.pojo.project.order.dto.UserOrderGoodsDTO;
import com.hb.core.pojo.project.order.entity.UserOrder;
import com.hb.core.pojo.project.order.entity.UserOrderGoods;
import com.hb.core.pojo.project.order.mapper.UserOrderGoodsMapper;
import com.hb.trade.server.project.order.service.UserOrderGoodsService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  订单信息商品 服务实现类
 * </p>
 *
 * @author zhongdl
 * @since 2021-12-22
 */
@Service
public class UserOrderGoodsServiceImpl extends ServiceImpl<UserOrderGoodsMapper, UserOrderGoods> implements UserOrderGoodsService {
    /**
     *
     * @Description: 获取当前企业
     * @Author: zhongdl
     * @Date:2022/2/21 19:02
     * @param feeType:收费类型
     * @param sectionId:标段id
     * @param orgId:企业id
     * @return: {@link UserOrderGoodsDTO }
     **/
    @Override
    public UserOrderGoodsDTO getUserOrderGoodsDTO(Integer feeType, Long sectionId, Long orgId) {
        if (feeType == null || sectionId == null || orgId == null){
            return null;
        }
        QueryWrapper<UserOrderGoods> wrapper = UserOrderGoods.wrapper();
        wrapper.eq("fee_type",feeType)
               .eq("section_id",sectionId)
               .eq("org_id",orgId)
                .orderByDesc("create_time")
                .last("limit 1");
        wrapper.orderByDesc("create_time");
        UserOrderGoods userOrderGoods = getOne(wrapper);
        if (userOrderGoods == null){
            return null;
        }
        return userOrderGoods.to(UserOrderGoodsDTO.class);
    }

}
